package trafficAgent;

import view.ViewThread;

import model.CityMap;
import jade.core.Agent;

public class TrafficAgent extends Agent {

	/**
	 * Run configuration
	 * 
	 * -cp jade.Boot  tAgent:trafficAgent.TrafficAgent
	 */
	private static final long serialVersionUID = 1L;
	
	private CityMap map;

	private ViewThread thread;
	
	private int behavStep = -1;
	
	private boolean running = false;
	
	private int carPerStep = 1;
	
	//Statistic
	private int menagedCar = 0;
	private int idleTime = 0;
	private int waitingTime = 0;
	
	
	
	
	public int getMenagedCar() {
		return menagedCar;
	}



	public int getIdleTime() {
		return idleTime;
	}



	public int getWaitingTime() {
		return waitingTime;
	}



	public void addMenagedCar() {
		this.menagedCar++;
	}



	public void addIdleTime(int idleTime) {
		this.idleTime += idleTime;
	}
	
	public void addWaitingTime(int waitingTime) {
		this.waitingTime += waitingTime;
	}
	
	public double getPerfMesure(){
		if(this.getMenagedCar() == 0)
			return 0;
		return (this.getIdleTime() + this.getWaitingTime()) / this.getMenagedCar();
	}



	public synchronized void setCarPerStep(int val){
		this.carPerStep = val;
	}
	
	
	
	public int getCarPerStep() {
		return carPerStep;
	}



	public synchronized void play()
	{
		this.running = true;
		addBehaviour(new MasterBehaviour(this));
	}
	
	public synchronized void stop()
	{
		this.running = false;
	}

	public synchronized boolean isRunning() {
		return running;
	}
	
	public int nextBehavStep(final int nStep){
		this.behavStep++;
		this.behavStep = behavStep % nStep;
		return this.behavStep;
	}
	
	public ViewThread getThread() {
		return thread;
	}

	public CityMap getMap() {
		return map;
	}
	
	@Override
	protected void setup() {
		super.setup();
		map = new CityMap();
		
		thread = new ViewThread(this);		
		thread.start();
		thread.doRepaint();
		
//		this.play();
		
		
	}

	public void doRepaint(){
		
	}


	
	
	
	
}
